<?php
namespace app\zbj\controller;
use think\Controller;
use think\Db;
use think\Request;
use think\Session;

class Login extends Controller
{

    public function index()
    {
        return view('Login/login');
    }

    public function dologin(Request $request)
    {
        $post=$request->post();
        $post=myarr($post);
//        dump($_POST);
//        dump(strtolower(session('yzcode')));die;
        if(strtolower($post['yzcode'])!=strtolower(session('yzcode'))){
            return "<script>alert('验证码错误');window.location.href = document.referrer</script>";
        }
        $res=Db::name('admin_user')->where(['username'=>$post['username'],'Backstage'=>2])->find();
        if($res['userpass']!=Md5('lc'.$post['password'])) return "<script>alert('账号或密码错误');history.go(-1)</script>";
        if($res['status']!=1) return "<script>alert('账号异常请联系客服');history.go(-1)</script>";
        Session::set('zbjUser',$res);
        return "<script>alert('登录成功');window.location.href='".url('Index/showindex')."'</script>";

    }

    public function exitlogin()
    {
        Session::clear();
//        $this->redirect('zbj/Login/index');
        return "<script>alert('退出登录成功');window.location.href='".url('zbj/Login/index')."'</script>";
    }

    public function yzm()
    {
        require_once EXTEND_PATH.'Validate/Validate.php';
        $validate=new \Validate();
        $c = $validate->code;
        session('yzcode',$c);
        $validate->doimg();


    }

}
